package ace.module.common.core.impl.properties;

import ace.module.common.api.constant.CommonConstants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

/**
 * module properties.
 *
 * @author Caspar
 */
@RefreshScope
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ConfigurationProperties(prefix = ModuleCommonSecurityProperties.CONFIG_PREFIX)
public class ModuleCommonSecurityProperties {

  public static final String CONFIG_PREFIX = "ace.module.common.security";

  /**
   * 运营管理平台账户应用id.
   */
  private Long iamAdminPlatformAppId = CommonConstants.DEFAULT_ADMIN_APP_ID;
  /**
   * 运营管理平台账户应用key.
   */
  private String iamAdminPlatformAppKey = CommonConstants.DEFAULT_ADMIN_APP_KEY;
  /**
   * 超级管理员基础账户id.
   */
  private Long iamAdministratorAccountId = CommonConstants.DEFAULT_ADMINISTRATOR_IAM_ACCOUNT_ID;
  /**
   * 运营管理平台权限应用id.
   */
  private Long upmsAdminPlatformAppId = CommonConstants.DEFAULT_ADMIN_APP_ID;
  /**
   * 运营管理平台权限应用key.
   */
  private String upmsAdminPlatformAppKey = CommonConstants.DEFAULT_ADMIN_APP_KEY;
  /**
   * 运营管理平台图形验证应用id.
   */
  private Long captchaAdminAppId = CommonConstants.DEFAULT_ADMIN_APP_ID;
  /**
   * 运营管理平台图形验证应用key.
   */
  private Long captchaAdminAppKEY = CommonConstants.DEFAULT_ADMIN_APP_ID;
  /**
   * oauth2应用的o redirect uri.
   */
  private String oauth2RedirectUri = "http://localhost:8080";
  /**
   * 运营管理平台rest 默认认证feign name.
   */
  private String oauth2AdminClientAuthenticationFeignName = "ace-app-web";
  /**
   * 运营管理平台rest 默认授权feign name.
   */
  private String oauth2AdminClientAuthorizationFeignName = "ace-app-web";
  /**
   * 系统默认oauth2认证协议的grant type
   */
  private String oauth2AceAuthenticationGrantType = "ace";
  /**
   * 运营管理平台oauth2 客户端id.
   */
  private String oauth2AdminClientId = CommonConstants.DEFAULT_ADMIN_CLIENT_CLIENT_ID;
  /**
   * 运营管理平台oauth2 客户端secret.
   */
  private String oauth2AdminClientSecret = CommonConstants.DEFAULT_ADMIN_CLIENT_CLIENT_SECRET;
  /**
   * 系统内部服务客户端clientId.
   */
  private String oauth2InternalServerClientId = CommonConstants.DEFAULT_INTERNAL_SERVER_CLIENT_CLIENT_ID;
  /**
   * 系统内部服务客户端clientSecret.
   */
  private String oauth2InternalServerClientSecret = CommonConstants.DEFAULT_INTERNAL_SERVER_CLIENT_CLIENT_SECRET;
  /**
   * 支持外部用户认证oauth2 客户端id.
   */
  private String oauth2ProxyExternalUserIdOfClient = CommonConstants.DEFAULT_PROXY_EXTERNAL_USER_CLIENT_ID;
  /**
   * 支持外部用户认证oauth2 客户端id.
   */
  private String oauth2ProxyExternalUserClientId = CommonConstants.DEFAULT_PROXY_EXTERNAL_USER_CLIENT_ID;
  /**
   * 支持外部用户认证oauth2 客户端secret.
   */
  private String oauth2ProxyExternalUserClientSecret = CommonConstants.DEFAULT_PROXY_EXTERNAL_USER_CLIENT_SECRET;
  /**
   * iam账户应用的oauth2 rest认证回调接口地址.
   */
  private String iamOauth2AuthenticationUrl = "http://localhost:8080/account/oauth2/rpc";

  /**
   * upms权限应用的oauth2 rest授权回调接口地址.
   */
  private String upmsOauth2AuthorizationUrl = "http://localhost:8080/upms/oauth2/rpc";
  /**
   * 超管理员账户名.
   */
  private String administratorUsername = CommonConstants.DEFAULT_ADMIN_ADMINISTRATOR_ACCOUNT_PASSPORT;
  /**
   * 超管理员账户密码.
   */
  private String administratorPassword = CommonConstants.DEFAULT_ADMIN_ADMINISTRATOR_ACCOUNT_PASSWORD;
  /**
   * 超管理员手机账户.
   */
  private String administratorPhone = CommonConstants.DEFAULT_ADMIN_ADMINISTRATOR_ACCOUNT_PASSPORT_PHONE;


  /**
   * 默认角色KEY前缀.
   */
  private String rolePrefix = "ROLE_";

  /**
   * 默认角色KEY前缀.
   */
  private String administratorRoleKeySuffix = "_ADMINISTRATOR__#SYSTEM#";

  public String getAdministratorRoleKey() {
    return this.rolePrefix + this.administratorRoleKeySuffix;
  }

}